//
//  MCNaviPopView.m
//  TLYL
//
//  Created by miaocai on 2017/7/28.
//  Copyright © 2017年 TLYL01. All rights reserved.
//

#import "MCNaviPopView.h"
@interface MCNaviPopView()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,weak) UITableView *tableView;

@property (nonatomic,assign) BOOL isShow;

@end

@implementation MCNaviPopView
- (void)showPopView{
    if (self.isShow) {
        [self hidePopView];
        return;
    }
    self.isShow = YES;
    [self.tableView reloadData];
    self.hidden = NO;

}
- (void)hidePopView{

    [UIView animateWithDuration:0.1  animations:^{

        self.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {
        self.hidden = YES;
        self.isShow =NO;
        
    }];
}
- (void)layoutSubviews{
    [super layoutSubviews];
    }
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return  self.dataSourceArray.count;
    }
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MCNaviPopView"];
    cell.textLabel.text = self.dataSourceArray[indexPath.row];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    
    cell.textLabel.font = [UIFont systemFontOfSize:12];
    cell.backgroundColor = RGB(48, 127, 207);
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (self.recordSelectedBlock) {
        self.recordSelectedBlock(indexPath.row);
        [self hidePopView];
    }

}
- (UITableView *)tableView{
    if (_tableView == nil) {
        UITableView *tab = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
        [self addSubview:tab];
        tab.rowHeight = 25;
        self.tableView = tab;
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"MCNaviPopView"];

    }
    return _tableView;
}
@end
